package server.jdbcdao;

import server.core.Right;
import server.dao.RightDAO;
import server.idatasource.DataSourceFactory;
import server.idatasource.IRightDataSource;

public class RightJdbcDAO implements RightDAO {

	/*Inserts a new right given as argument, into the database. Returns a string, with the
	 * value "OK" if the operation was successful, else returns "ERROR".*/
	@Override
	public String insertRight(Right right) {
		DataSourceFactory ds = DataSourceFactory.getInstance();
		IRightDataSource rightData = ds.getRightDataSource();

		return rightData.insertRight(right.getId(), right.getName());
	}

	@Override
	/*Deletes a right from database, having the rightID given as argument. Returns a string, with the
	 * value "OK" if the operation was successful, else returns "ERROR".*/
	public String deleteRight(int rightId) {
		DataSourceFactory ds = DataSourceFactory.getInstance();
		IRightDataSource rightData = ds.getRightDataSource();

		return rightData.deleteRight(rightId);
	}

	/*Updates the user given in the argument, in the database. Returns a string, with the
	 * value "OK" if the operation was successful, else returns "ERROR".*/
	@Override
	public String updateRight(Right right) {
		DataSourceFactory ds = DataSourceFactory.getInstance();
		IRightDataSource rightData = ds.getRightDataSource();

		return rightData.updateRight(right.getId(), right.getName());
	}
}
